home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_dev-disk / egsdemos / egsexamples / requester / file / requester.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  2.9 KB  |  196 lines

  1. /*
  2. *
  3. *  $
  4. *  $ FILE     : requester.c
  5. *  $ VERSION  : 1
  6. *  $ REVISION : 4
  7. *  $ DATE     : 08-Dec-93 21:26
  8. *  $
  9. *  $ Author   : mvk
  10. *  $
  11. *
  12. *
  13. **   This example shows how to work with the egsrequest.library.
  14. **
  15. **  The routines myError,myMSG and EventLoop opens
  16. **  the requester.
  17. **
  18. **  (c) by VIONA-Development 1992/94
  19. **
  20. */
  21.  
  22.  
  23. /*
  24. ** Init-Routines
  25. */
  26.  
  27. #include "Global.h"
  28. #include "EventLoop.c"
  29. #include "makegadget.c"
  30.  
  31. BOOL InitLibraries(struct OpenStructTyp *OS)
  32. {
  33.  struct OpenStructTyp *p = &OS[0];
  34.  
  35.  while (p->Var != NULL)
  36.  {
  37.    if ((*(p->Var) = (ULONG)OpenLibrary(p->Name,p->Version)) == NULL)
  38.        {
  39.        printf(" Can't open %s version %d",p->Name, p->Version);
  40.        return FALSE;
  41.        }
  42.        else
  43.        {  p ++; }
  44.  }
  45.    return TRUE;
  46. }
  47. /**/
  48.  
  49. void CloseLibraries(struct OpenStructTyp *OS)
  50. {
  51.  struct OpenStructTyp *p = &OS[0];
  52.  
  53.  while (p->Name != NULL)
  54.  {
  55.     CloseLibrary((void *)(*(p->Var)));
  56.     *(p->Var) = NULL;
  57.     p++;
  58.  }
  59. }
  60. /**/
  61.  
  62.  
  63. /*
  64. **  Open a Requester in the middle of
  65. **  the Screen.
  66. **
  67. */
  68.  
  69. void myMSG(char *string)
  70. {
  71.   if ( string != NULL)
  72.   {
  73.      if ( EGSRequestBase == NULL)
  74.       {
  75.       printf("%s\n",string);
  76.  
  77.       }else{
  78.  
  79.      ErrorReq = (ER_SimpleReqPtr)ER_CreateSimpleReq(NULL,
  80.                       (char *)string,(char *)"OK");
  81.  
  82.      /*
  83.      **  Open Requester in the middle of the Screen,
  84.      **
  85.      **  if you could !?
  86.      */
  87.  
  88.      ErrorReq->Req.Nw->Flags |= EI_WINDOWCENTER;
  89. /*
  90.      ErrorReq->Req.Nw->LeftEdge = Window->LeftEdge;
  91.      ErrorReq->Req.Nw->TopEdge  = Window->TopEdge;
  92. */
  93.      ErrorReq->Req.Nw->Title  ="eInputRecorder";
  94.      ER_DoRequest(&(ErrorReq->Req)) ;
  95.       }
  96.   }
  97. }
  98.  
  99. /*
  100.  * Author: Markus van Kempen
  101.  * Date  : 9. November 92
  102.  *
  103.  * This routine is for Errorhandling.
  104.  * It close all open thinks form the
  105.  * program.
  106.  *
  107.  * if ende == TRUE the myError terminates
  108.  *            otherwise it returns
  109.  *
  110.  */
  111. void myError(char *string,int ende)
  112. {
  113.  
  114.   myMSG("Hello world !|This is a Requester !");
  115.  
  116.   myMSG(string);
  117.  
  118.   if ( Window != NULL )
  119.      EI_CloseWindow(Window);
  120.  
  121.   if ( con != NULL )
  122.     EB_DeleteGadContext(con);
  123.  
  124.   if ( FontforMenu != NULL )
  125.     EG_CloseFont(FontforMenu);
  126.  
  127.   if ( Menu != NULL )
  128.     EI_FreeMenu(Menu);
  129.  
  130.   if ( ErrorReq != NULL )
  131.      ER_DeleteRequest(&(ErrorReq->Req));
  132.  
  133.   CloseLibraries(OpenStruct);
  134.  
  135.   if (ende)
  136.        exit(0);
  137.  
  138. }
  139. /**/
  140.  
  141.  
  142. /*
  143. **  myopen  = It Opens all egs libraries
  144. **            and calls InitMenu from initmenu.c
  145. **            and calls CreateGads from makegadgets.c
  146. **
  147. **
  148. */
  149.  
  150. struct EI_Window *myopen(void)
  151. {
  152. struct EI_Window     *Window=NULL;
  153.  
  154.       if ( InitLibraries(OpenStruct) == FALSE)
  155.       myError("Can't OpenLibrary",10);
  156.  
  157.  
  158. /*
  159.       SEE Init_Menu.c
  160.  
  161.       Menu=InitMenu(FontforMenu);
  162.  
  163.  
  164.       if ( Menu == NULL )
  165.       myError("Could not build Menu",10);
  166.  
  167. */
  168.  
  169.       Window=CreateGads(NULL);
  170.  
  171.      if (Window == NULL)
  172.            myError("Could not open window",10);
  173.   return(Window);
  174. }
  175.  
  176.  
  177. /*
  178. **
  179. **   start GUI
  180. **
  181. */
  182.  
  183. void main(void)
  184. {
  185.      Window=myopen();    /* see myopen.c */
  186.  
  187.      if(Window)
  188.         HandleEvents(Window);
  189.  
  190.     myError(NULL,10);
  191. }
  192.  
  193. /* ENDE */
  194.  
  195.  
  196.